package com.woniuxy.order.service.impl;

import com.rabbitmq.client.Channel;
import com.woniuxy.order.entity.SecondhouseOrder;
import com.woniuxy.order.mapper.SecondhouseOrderMapper;
import com.woniuxy.order.service.SecondhouseOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.order.util.OrderNumberCreator;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author maotao
 * @since 2021-03-19
 */
@Service
public class SecondhouseOrderServiceImpl extends ServiceImpl<SecondhouseOrderMapper, SecondhouseOrder> implements SecondhouseOrderService {
    @Autowired
    SecondhouseOrderService secondhouseOrderService;
    @Autowired
    SecondhouseOrderMapper orderMapper;

    @RabbitListener(queues = "topic.second")
    public void add(SecondhouseOrder order, Channel channel, Message message) throws IOException {


        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        String orderNum = OrderNumberCreator.createServerOrderNum();
        order.setOrderno(orderNum)
                .setTime(LocalDateTime.now())
                .setStatus(0);
        orderMapper.insert(order);

    }
}
